const { createClient } = require('redis')

const client = createClient({
  url: process.env.LOCAL_REDIS,
})

client.on('error', (err) => {
  console.log('Redis 连接失败 ❌', err)
})

// 封装连接函数
client.connectRedis = async () => {
  if (!client.isOpen) {
    await client.connect()
  }
}

module.exports = client
